package fr.umlv.ig.extraWindows;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


/**
 * Creates a ExtraXindow to know if the user want to leave the application
 * if the request is ExitCurrentGame.EXIT if you pressed OK the program is 
 * over else the windows is close.
 */
@SuppressWarnings("serial")
public class ExitApplicationWindow extends ExtraWindow {

	/**
	 * Creates a ExtraXindow to know if the user want to leave the application.
	 * @param owner owner's frame
	 */
	public ExitApplicationWindow(JFrame owner, String title) {
		super(owner, title, true, 260, 200);
		init(owner);
		dispose();
	}
	
	
	/**
	 * Initializes the components in the windows.
	 */
	private void init(JFrame frame) {
		JPanel p = new JPanel(new BorderLayout());
	
		
		JLabel quitLabel= new JLabel("Exit Jacques Beauheur?");
		
		p.add(quitLabel);
		
		
		final JButton confirmButton = new JButton("Ok");
		confirmButton.addActionListener(quit(frame));
		p.add(confirmButton);
		
	
		final JButton cancelButton = new JButton("Cancel");
		cancelButton.addActionListener(dialogListner);
		
		JPanel panelNorth = new JPanel();
		panelNorth.add(confirmButton);
		panelNorth.add(cancelButton);
		
		p.add(panelNorth,BorderLayout.SOUTH);
		add(p);
	}

	@Override
	public void start() {
		setLocationRelativeTo(getOwner());
		setVisible(true);
		
	}
	
	/**
	 * Listener used for the button ok to leave the application.
	 * @param the frame of the application to close or not.
	 * @return the frame of the application to close or not.
	 */
	private ActionListener quit(final JFrame frame) {
		return new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		};
	}



}
